<!DOCTYPE html>
<html lang="en" xmlns:th="https://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <title>
        字典数据维护
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/assets/admin/css/font.css}">
    <link rel="stylesheet" th:href="@{/assets/admin/css/xadmin.css}">
    <script th:src="@{/assets/admin/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/assets/admin/js/xadmin.js}"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style type="text/css">
        input::-webkit-outer-spin-button,input::-webkit-inner-spin-button{

            -webkit-appearance: none !important;

        }/* chrome */

        input[type="number"]{

            -moz-appearance:textfield;/* firefox */

        }
    </style>
</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="no" class="layui-form-label">
                <span class="x-red">  </span>
            </label>
            <input type="hidden" id="parentId" name="parentId" th:value="${parentId == null?(dictData == null ? '':dictData.parentId):parentId }"/>
            <input type="hidden" id="id" name="id" th:value="${dictData ==null?'':dictData.id}" />
        </div>
        <div class="layui-form-item" style="margin-top: 25px">
            <label for="dataName" class="layui-form-label">
                <span class="x-red">*</span>名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="dataName" name="dataName" lay-verify="required"
                       autocomplete="off" class="layui-input" th:value="${dictData == null?'':dictData.dataName}">
            </div>
        </div>
        <div class="layui-form-item" style="margin-top: 25px">
            <label for="dataValue" class="layui-form-label">
                <span class="x-red">*</span>数据值
            </label>
            <div class="layui-input-inline">
                <input type="text" id="dataValue" name="dataValue" lay-verify="required"
                       autocomplete="off" class="layui-input"  th:value="${dictData == null?'':dictData.dataValue}">
            </div>
        </div>
        <div class="layui-form-item" style="margin-top: 25px">
            <label for="remarks" class="layui-form-label">
                备注
            </label>
            <div class="layui-input-inline">
                <input type="text" id="remarks" name="remarks" autocomplete="off" class="layui-input" th:value="${dictData == null?'':(dictData.remarks)}">
            </div>
        </div>
        <div class="layui-form-item" style="margin-top: 25px">
            <label for="no" class="layui-form-label">
                <span class="x-red">*</span>排序值
            </label>
            <div class="layui-input-inline">
                <input type="number" id="no" name="no" lay-verify="required"
                       autocomplete="off" class="layui-input" th:value="${dictData == null?'':(dictData.no)}">
            </div>
        </div>
        <div class="layui-form-item" style="margin-top: 25px">
            <div class="layui-inline">
                <label for="no" class="layui-form-label">
                    <span class="x-red">*</span>有效日期
                </label>
                <div class="layui-input-inline">
                    <input  id="effectiveDate"  name="effectiveDate" lay-verify="required"
                           autocomplete="off" class="layui-input" th:value="${dictData == null?'':#dates.format(dictData.effectiveDate,'yyyy-MM-dd')}">
                </div>
                <div class="layui-form-mid">
                    <span>-</span>
                </div>
                <div class="layui-input-inline">
                    <input  id="expirationDate"  name="expirationDate" lay-verify="required"
                           autocomplete="off" class="layui-input" th:value="${dictData == null?'':#dates.format(dictData.expirationDate,'yyyy-MM-dd')}">
                </div>
            </div>
        </div>

        <div class="layui-form-item" style="text-align: center">
            <button th:if="${dictData == null}" class="layui-btn" lay-filter="add" lay-submit>
                增加
            </button>
            <button th:if="${dictData != null}" class="layui-btn" lay-filter="update" lay-submit>
                更新
            </button>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layer','laydate'], function () {
        $ = layui.jquery;
        form = layui.form;
        laydate = layui.laydate;
        layer = layui.layer;
        //执行一个laydate实例
        laydate.render({
            elem: '#effectiveDate', //指定元素
            showBottom:false,
            format:"yyyy-MM-dd"
        });
        laydate.render({
            elem: '#expirationDate',
            showBottom:false,
            format:"yyyy-MM-dd"
        });


        //监听提交
        form.on('submit(add)', function (data) {
            //console.log(typeof data.field);
            //发异步，把数据提交给后台处理
            $.ajax({
                url: "/system/addDictData",
                data: JSON.stringify(data.field),
                type: "post",
                dataType: "json",
                contentType: "application/json;charset=utf-8",
                success: function (data) {
                    //console.log(data.message);
                    if (data.code == 200) {
                        layer.alert(data.message, {icon: 6}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    } else {
                        layer.alert(data.message, {icon: 5}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    }
                }
            });
            return false;
        });

        form.on('submit(update)', function (data) {
            //console.log(typeof data.field);
            //发异步，把数据提交给后台处理
            $.ajax({
                url: "/system/updateDictData",
                data: JSON.stringify(data.field),
                type: "post",
                dataType: "json",
                contentType: "application/json;charset=utf-8",
                success: function (data) {
                    //console.log(data.message);
                    if (data.code == 200) {
                        layer.alert(data.message, {icon: 6}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    } else {
                        layer.alert(data.message, {icon: 5}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    }
                }
            });
            return false;
        });
    });
</script>

</body>

</html>